package com.huawei.appgallery.forum.user.usercenter.activity;

import android.app.ActionBar;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabDetailResponse;
import com.huawei.appgallery.forum.base.ui.ForumActivity;
import com.huawei.appgallery.forum.user.api.IUserHomePageProtocol;
import com.huawei.appgallery.forum.user.menu.MenuLinearLayout;
import com.huawei.appgallery.forum.user.menu.UserActionBar;
import com.huawei.appgallery.forum.user.usercenter.bean.ForumUserHeadCardBean;
import com.huawei.appgallery.forum.user.usercenter.fragment.UserHomeExceptionCaseFragment;
import com.huawei.appgallery.forum.user.usercenter.fragment.UserHomePageFragment.a;
import com.huawei.appgallery.forum.user.userinfo.activity.PersonalDataActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment.c;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.e;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.hmf.annotation.ActivityDefine;
import huawei.widget.HwTextView;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import o.ayw;
import o.azb;
import o.bqx;
import o.brm;
import o.bsv;
import o.cbb;
import o.cbb.d;
import o.cbb.j;
import o.cbt;
import o.cbu;
import o.cbv;
import o.cbx;
import o.AccountBussinessListener;
import o.ccp;
import o.cgv;
import o.cia;
import o.cir;
import o.cjk;
import o.cjm;
import o.cvt;
import o.doo;
import o.eoj;
import o.ActivityUtil;
import o.evk;
import o.fho;
import o.fiu;
import o.fiv;
import o.fjb;
import o.fjm;
import o.FragmentTransaction;

@ActivityDefine(alias = "UserHomePageActivity", protocol = IUserHomePageProtocol.class)
public class UserHomePageActivity extends ForumActivity implements OnClickListener, e, cbv, c, AccountBussinessListener, a {
    private static final Object ˊᐝ = new Object();
    private String ʻॱ;
    private cbx ʽॱ;
    private JGWTabDetailResponse ʾ;
    private HwTextView ʿ;
    private LinearLayout ˈ;
    private Handler ˉ = new Handler();
    private Map<Integer, cia> ˊˊ = new HashMap();
    private String ˊˋ;
    private UserActionBar ˋˊ;
    private boolean ˋˋ = false;
    private fiv ˋॱ = fiv.ॱ(this);
    private int ˋᐝ = -1;
    private int ˌ = -1;
    private boolean ˍ = false;
    private TaskFragment ˎˎ;
    private int ˏˏ = -1;
    protected long ͺ = 0;
    private o.cbr.b ͺॱ = new o.cbr.b(this) {
        final /* synthetic */ UserHomePageActivity ˏ;

        {
            this.ˏ = r1;
        }

        public void ˊ() {
            Intent intent = new Intent();
            intent.setClass(this.ˏ, PersonalDataActivity.class);
            try {
                this.ˏ.startActivityForResult(intent, 11);
            } catch (ActivityNotFoundException e) {
                bqx.ˋ("UserHomePageActivity", "ActivityNotFoundException :" + e.toString());
            }
        }
    };
    private String ॱˊ = null;
    private String ॱˋ = "";
    private String ॱˎ = null;
    private int ᐝॱ = 0;

    static class b implements Runnable {
        private WeakReference<UserHomePageActivity> ˋ;
        private int ॱ;

        b(UserHomePageActivity userHomePageActivity, int i) {
            this.ˋ = new WeakReference(userHomePageActivity);
            this.ॱ = i;
        }

        public void run() {
            UserHomePageActivity userHomePageActivity = (UserHomePageActivity) this.ˋ.get();
            if (userHomePageActivity == null) {
                bqx.ˊ("UserHomePageActivity", "ReloadRunnable userHomePageActivity null");
            } else if (103 == this.ॱ && userHomePageActivity.ˊᐝ()) {
                bqx.ˊ("UserHomePageActivity", "ACCOUNT_LOGOUT_SUCCESS finish myself");
                userHomePageActivity.finish();
            } else {
                synchronized (UserHomePageActivity.ˊᐝ) {
                    long currentTimeMillis = System.currentTimeMillis();
                    if (userHomePageActivity.ͺ == 0 || currentTimeMillis - userHomePageActivity.ͺ >= 2000) {
                        userHomePageActivity.ͺ = currentTimeMillis;
                        userHomePageActivity.ˊˊ();
                        return;
                    }
                    bqx.ˊ("UserHomePageActivity", "onAccountBusinessResult, account interval too short.");
                }
            }
        }
    }

    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        eoj.ˋ().ˎ("UserHomePageActivity", this);
        ͺ();
        ˎ(bundle);
    }

    private void ͺ() {
        cgv.ˋ(this, cbb.c.ॱ, cbb.c.ᐝ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(cbb.c.ᐝ));
        setContentView(d.ˋ);
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        this.ˈ = (LinearLayout) findViewById(o.cbb.b.ˋˋ);
        azb.ˏ(this.ˈ);
        this.ʿ = (HwTextView) this.ˈ.findViewById(o.cbb.b.ʽˊ);
        this.ˈ.findViewById(o.cbb.b.ˏ).setOnClickListener(this);
        this.ˋˊ = (UserActionBar) findViewById(o.cbb.b.ˊˊ);
        cbt.ˋ().ˎ(this.ˋˊ.ˏ(), this.ͺॱ);
    }

    private void ˎ(@Nullable Bundle bundle) {
        Object ab_ = ab_();
        if (ab_ instanceof Map) {
            this.ˊˊ = (Map) ab_;
        }
        IUserHomePageProtocol iUserHomePageProtocol = (IUserHomePageProtocol) this.ˋॱ.ॱ();
        this.ॱˊ = iUserHomePageProtocol.getUri();
        this.ˊˋ = iUserHomePageProtocol.getDomainId();
        this.ॱˋ = iUserHomePageProtocol.getUserId();
        this.ᐝॱ = iUserHomePageProtocol.getType();
        this.ॱˎ = cbu.ˏ(this, this.ᐝॱ);
        this.ʻॱ = iUserHomePageProtocol.getHeadUri();
        if (TextUtils.isEmpty(this.ʻॱ)) {
            if (this.ᐝॱ == 1) {
                this.ॱˋ = "";
                this.ʻॱ = cbu.ॱ("forum|user_detail", this.ॱˋ);
            } else if (this.ॱˋ == null) {
                ˎ(400012);
                return;
            } else {
                this.ʻॱ = cbu.ॱ("forum|user_detail", this.ॱˋ);
            }
        }
        if (bundle == null) {
            ॱˊ();
            return;
        }
        this.ʻॱ = bundle.getString("bundle_uri");
        this.ॱˋ = bundle.getString("bundle_userid");
        this.ʾ = (JGWTabDetailResponse) bundle.getSerializable("bundle_responsebean");
        this.ˍ = bundle.getBoolean("bundle_datasuccess");
        this.ˋˋ = bundle.getBoolean("bundle_usererror");
        this.ˌ = bundle.getInt("save_bundle_key_lastScroll");
        this.ˏˏ = bundle.getInt("save_bundle_key_lastTab");
        Fragment findFragmentByTag = ˏॱ().findFragmentByTag("TaskFragment");
        if (findFragmentByTag instanceof TaskFragment) {
            this.ˎˎ = (TaskFragment) findFragmentByTag;
        }
        if (this.ˍ) {
            ˏ(ॱ(this.ʾ));
        } else if (this.ˋˋ) {
            this.ʿ.setText(this.ॱˎ);
        } else {
            this.ʿ.setText(j.ˊ);
        }
    }

    private ForumUserHeadCardBean ॱ(JGWTabDetailResponse jGWTabDetailResponse) {
        if (jGWTabDetailResponse == null) {
            return null;
        }
        List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
        if (ᐝॱ == null || ᐝॱ.size() <= 0) {
            bqx.ˋ("UserHomePageActivity", "layoutDataList is empty");
            return null;
        }
        ForumUserHeadCardBean forumUserHeadCardBean;
        for (LayoutData layoutData : ᐝॱ) {
            if (layoutData.ˋ() == null) {
                bqx.ˋ("UserHomePageActivity", "layoutdata.datalist is null, layoutid:" + layoutData.ˎ());
            } else if (layoutData.ˋ() != null && layoutData.ˋ().size() > 0) {
                CardBean cardBean = (CardBean) layoutData.ˋ().get(0);
                if (cardBean instanceof ForumUserHeadCardBean) {
                    forumUserHeadCardBean = (ForumUserHeadCardBean) cardBean;
                    break;
                }
            }
        }
        forumUserHeadCardBean = null;
        return forumUserHeadCardBean;
    }

    public void onClick(View view) {
        if (o.cbb.b.ˏ == view.getId()) {
            finish();
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        if (i == 11 && i2 == -1) {
            String stringExtra = intent.getStringExtra("headPic");
            String stringExtra2 = intent.getStringExtra("nickname");
            ForumUserHeadCardBean ॱ = ॱ(this.ʾ);
            if (ॱ != null) {
                User ˊ = ॱ.ˊ();
                if (ˊ != null) {
                    ˊ.ˎ(stringExtra2);
                    ˊ.ˋ(stringExtra);
                }
            }
            this.ʽॱ.ˊ(stringExtra, stringExtra2);
        }
    }

    public void ॱ(cbx o_cbx) {
        this.ʽॱ = o_cbx;
    }

    private void ॱˊ() {
        this.ʿ.setText(j.ˊ);
        Fragment ˊ = cjk.ˎ().ˊ(new cjm("user_loading_.fragment", null));
        if (ˊ instanceof TaskFragment) {
            this.ˎˎ = (TaskFragment) ˊ;
            this.ˎˎ.ˋ(ˏॱ(), o.cbb.b.ˋʻ, "TaskFragment");
        }
    }

    private void ᐝॱ() {
        if (this.ˎˎ != null) {
            this.ˎˎ.ॱ(ˏॱ());
        } else {
            findViewById(o.cbb.b.ˋʻ).setVisibility(8);
        }
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        if (!TextUtils.isEmpty(this.ʻॱ)) {
            list.add(new brm.e(this.ʻॱ).ˏ(bsv.ॱ(this.ˊˋ)).ॱ());
        }
    }

    public boolean ˋ(TaskFragment taskFragment, com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        if (!ActivityUtil.isAcitivtyNotValid(this)) {
            if (bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0) {
                this.ʾ = (JGWTabDetailResponse) bVar.ˋ;
                ForumUserHeadCardBean ॱ = ॱ(this.ʾ);
                if (ॱ(ॱ)) {
                    this.ˋˋ = true;
                    ˎ(400012);
                } else {
                    this.ˍ = true;
                    ˋ(ॱ);
                }
            } else {
                ˏ(taskFragment, bVar);
            }
        }
        return false;
    }

    private void ˋ(ForumUserHeadCardBean forumUserHeadCardBean) {
        ˏ(forumUserHeadCardBean);
        fjb ˎ = fho.ˏ().ˋ("User").ˎ("UserHomePageFragment");
        IUserHomePageProtocol iUserHomePageProtocol = (IUserHomePageProtocol) ˎ.ˊ();
        iUserHomePageProtocol.setUri(this.ॱˊ);
        iUserHomePageProtocol.setResponseBean(this.ʾ);
        iUserHomePageProtocol.setDomainId(this.ˊˋ);
        iUserHomePageProtocol.setUserId(this.ॱˋ);
        iUserHomePageProtocol.setType(this.ᐝॱ);
        iUserHomePageProtocol.setLastScroll(this.ˌ);
        iUserHomePageProtocol.setLastSelectTab(this.ˏˏ);
        fjm ˏ = fjm.ˏ(fiu.ˊ().ˋ(this, ˎ));
        FragmentTransaction ˊ = ˏॱ().ˊ();
        ˊ.ˏ(o.cbb.b.ˊʽ, ˏ.ˏ(), "userhome_page_tag");
        ˊ.ˋ();
    }

    private void ˏ(ForumUserHeadCardBean forumUserHeadCardBean) {
        ᐝॱ();
        ʼॱ();
        ˎ(forumUserHeadCardBean);
        if (this.ˌ >= 0 && this.ˋᐝ >= 0) {
            ˊ(this.ˌ, this.ˋᐝ);
        }
    }

    private void ʼॱ() {
        this.ˈ.setVisibility(8);
        if (VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            ayw.ˏ(this, 16908290, null, false);
            cgv.ˋ(window);
            if (cgv.ˎ()) {
                cgv.ˏ(window, 1);
            } else {
                window.setStatusBarColor(-16777216);
            }
        }
        View findViewById = getWindow().getDecorView().findViewById(16908335);
        if (findViewById != null) {
            findViewById.setVisibility(8);
        }
    }

    private void ˎ(ForumUserHeadCardBean forumUserHeadCardBean) {
        boolean z;
        int i = 0;
        if (forumUserHeadCardBean == null || forumUserHeadCardBean.ˊ() == null) {
            z = false;
        } else {
            z = forumUserHeadCardBean.ˊ().ʼ();
            this.ॱˎ = cbu.ˏ(this, forumUserHeadCardBean.ˊ().ˊ());
        }
        this.ˋˊ.setTitle(this.ॱˎ);
        this.ˋˊ.setVisibility(0);
        MenuLinearLayout ˏ = this.ˋˊ.ˏ();
        if (!z) {
            i = 8;
        }
        ˏ.setVisibility(i);
    }

    private void ˏ(TaskFragment taskFragment, com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        cir o_cir = null;
        if (taskFragment != null) {
            o_cir = (cir) taskFragment.ˊ(cir.class);
        }
        if (ˊ(bVar)) {
            this.ˋˋ = true;
            ˎ(bVar.ˋ.getRtnCode_());
        } else if (o_cir != null) {
            o_cir.ॱ(ˋ(bVar.ˋ), true);
        }
    }

    private boolean ॱ(ForumUserHeadCardBean forumUserHeadCardBean) {
        return forumUserHeadCardBean == null || forumUserHeadCardBean.ˊ() == null;
    }

    private void ˎ(int i) {
        try {
            ᐝॱ();
            this.ʿ.setText(this.ॱˎ);
            Fragment userHomeExceptionCaseFragment = new UserHomeExceptionCaseFragment();
            userHomeExceptionCaseFragment.ˋ(i);
            FragmentTransaction ˊ = ˏॱ().ˊ();
            ˊ.ˏ(o.cbb.b.ˊʽ, userHomeExceptionCaseFragment, "UserHomePageActivity");
            ˊ.ˋ();
        } catch (Exception e) {
            bqx.ˋ("UserHomePageActivity", "showExceptionCaseFragment exception");
        }
    }

    private boolean ˊ(com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        boolean z = bVar.ˋ.getResponseCode() == 0;
        boolean z2;
        if (bVar.ˋ.getRtnCode_() == 400001 || bVar.ˋ.getRtnCode_() == 400006 || bVar.ˋ.getRtnCode_() == 400007 || bVar.ˋ.getRtnCode_() == 400008 || bVar.ˋ.getRtnCode_() == 400011 || bVar.ˋ.getRtnCode_() == 400012 || bVar.ˋ.getRtnCode_() == 400016) {
            z2 = true;
        } else {
            z2 = false;
        }
        if (z && r3) {
            return true;
        }
        return false;
    }

    private int ˋ(ResponseBean responseBean) {
        int responseCode = responseBean.getResponseCode();
        if (responseCode != 0 || responseBean.getRtnCode_() == 0) {
            return responseCode;
        }
        return 1;
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putString("bundle_uri", this.ʻॱ);
        bundle.putString("bundle_userid", this.ॱˋ);
        bundle.putSerializable("bundle_responsebean", this.ʾ);
        bundle.putBoolean("bundle_datasuccess", this.ˍ);
        bundle.putBoolean("bundle_usererror", this.ˋˋ);
        bundle.putInt("save_bundle_key_lastScroll", this.ˌ);
        bundle.putInt("save_bundle_key_lastTab", this.ˏˏ);
        super.onSaveInstanceState(bundle);
    }

    public void ˊ(int i, int i2) {
        if (this.ˋˊ != null) {
            this.ˌ = i;
            this.ˋᐝ = i2;
            this.ˋˊ.ˏ(i, i2);
        }
    }

    public cia ॱ(int i) {
        return (cia) this.ˊˊ.get(Integer.valueOf(i));
    }

    public void ˋ(int i, cia o_cia) {
        bqx.ˊ("UserHomePageActivity", "set Cache Provider:" + i);
        this.ˊˊ.put(Integer.valueOf(i), o_cia);
    }

    public Object T_() {
        return this.ˊˊ;
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        if (102 == o_ccp.ˎ || 103 == o_ccp.ˎ) {
            bqx.ˊ("UserHomePageActivity", "onAccountBusinessResult, login status: " + o_ccp);
            this.ˉ.postDelayed(new b(this, o_ccp.ˎ), 500);
        }
    }

    private void ˊˊ() {
        if (ActivityUtil.isAcitivtyNotValid(this)) {
            bqx.ॱ("UserHomePageActivity", "notifyDataChanged, activity is destroy");
        } else if (doo.ˊ((Context) this)) {
            ˊˋ();
        } else {
            evk.ˋ(this, getString(j.ͺॱ), 0).ˋ();
        }
    }

    private void ˊˋ() {
        ˉ();
        this.ˌ = 0;
        if (this.ˎˎ != null) {
            this.ˎˎ.ॱˋ(false);
            this.ˎˎ.ʾˋ();
        } else if (this.ॱˋ != null) {
            ॱˊ();
        }
    }

    private void ˉ() {
        if (this.ˊˊ != null) {
            this.ˊˊ.clear();
        }
    }

    public void onDestroy() {
        eoj.ˋ().ˊ("UserHomePageActivity");
        super.onDestroy();
    }

    public void ˏ(int i) {
        this.ˏˏ = i;
    }

    private boolean ˊᐝ() {
        ForumUserHeadCardBean ॱ = ॱ(this.ʾ);
        if (ॱ == null || ॱ.ˊ() == null) {
            return false;
        }
        return ॱ.ˊ().ʼ();
    }
}
